<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="__static__/admin/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="__static__/admin/js/jquery.js"></script>
</head>

<body>

	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="#">首页</a></li>
    <li><a href="#">表单</a></li>
    </ul>
    </div>
    
    <div class="formbody">
    
    <div class="formtitle"><span>管理员信息</span></div>
    <form id="AdminInfo">
        <ul class="forminfo">
            <li>
                <button style="width: 60px;height: 60px; position: relative;">
                <img id="Head_portrait" src="{$admin_info.Head_portrait}" width="60" height="60"/>
                <br/>
                <input type="file" style="opacity: 0;width: 60px;height: 60px; position: absolute; top: 0;left: 0;" onchange="uploadPic(this)">
                </button>
                <input type="hidden" name="Head_portrait" value="{$admin_info.Head_portrait}">
            </li>
            <li><label>用户名</label><input name="Username" value="{$admin_info.Username}" type="text" disabled="disabled" class="dfinput" /><i>用户名不能超过30个字符</i></li>
            <li><label>修改密码</label><input name="Password" value="{$admin_info.Password}" type="password" class="dfinput" /><i>密码不能超过50个字符</i></li>
            <li><label>联系方式</label><input value="{$admin_info.Contact}" name="Contact" type="text" class="dfinput" value="http://www..com/html/uidesign/" /></li>
            <li><label>&nbsp;</label><input name="" type="button" class="btn" onclick="editAdminInfo({$admin_info.id},'{$admin_info.Username}')" value="确认保存"/></li>
        </ul>
    </form>
    
    </div>
</body>
</html>
<script>
    function editAdminInfo(id,Username){
        var d = {};
        var t = $("#AdminInfo").serializeArray();
        $.each(t, function () {
            d[this.name] = this.value;
        });
        if(d.Password=='') return alert('密码不能为空');
        d.Username = Username;
        d.id = id;

        console.log('表单数据',d)
        $.post('{:url("editAdminInfo")}',{data:d},function(res){
            console.log('返回数据',res)
            alert(res.msg)
            window.location.reload();
        })
    }
    var file_data = [];
    function uploadPic(obj){
        if (window.FileReader) {
          var reader = new FileReader();
        } else {
          alert("您的设备不支持图片预览功能，如需该功能请升级您的设备！");
        }
        var imageType = /^image\//;
        var files=obj.files;//获取文件流
        var val= obj.value;
        var url = '';
        that = obj;
        //data = files;
        for(var i=0; i<files.length;i++){
            var file = files[i];
            var suffix = file.type.split('/')[1];
            //var storeAs = "studio_course/"+timestamp()+"."+suffix;
            var storeAs = "studio_course/"+file.name;
            var reader = new FileReader();
            reader.readAsDataURL(file);
            //读取完成  

            // client.multipartUpload(storeAs, file).then(function (result) {
            //  console.log('成功',result);
            // }).catch(function (err) {
            //  console.log('错误',err);
            // });
            reader.onload = function(e) {
                if(e.target.result){
                    if (imageType.test(file.type)) url = e.target.result;
                    file_data.push(e.target.result);
                    $.post('{:url("uploadFileLocal")}',{file:e.target.result,fileName:'{$admin_info.Username}'},function(res){
                        console.log('返回信息',res)
                        alert(res.msg)
                        if(res.code == 1)
                        $('#Head_portrait').attr('src',res.data);
                        $('input[name="Head_portrait"]').val(res.data);
                    })
                }
          };   
        }
    }
</script>